﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nature.Data.CkMarkup
{
    public partial class CkReaction
    {
        public IEnumerable<CkReagent> FwdReagents
        {
            get { return this.ReactionEquation.FwdReaction.Reagents; }
        }

        public IEnumerable<CkReagent> RevReagents
        {
            get { return this.ReactionEquation.RevReaction.Reagents; }
        }

        public string ThirdBody
        {
            get { return this.ReactionEquation.ThirdBody; }
        }

        public bool HasThirdBody
        {
            get
            {
                return (!string.IsNullOrWhiteSpace(this.ThirdBody));
            }
        }

        public bool HasReagent(string reagentID)
        {
            return FwdReagents.Any(i => i.ReagentID == reagentID) ||
                RevReagents.Any(i => i.ReagentID == reagentID);
        }

        public double GetReagentProduction(string reagentID)
        {
            return RevReagents.GetReagentStoichiometricCoefficient(reagentID) -
                FwdReagents.GetReagentStoichiometricCoefficient(reagentID);
        }

        public bool IsReversible
        {
            get { return this.ReactionEquation.IsReversible; }
        }

        public IEnumerable<CkReagent> Reagents
        {
            get { return FwdReagents.Union(RevReagents);  }
        }

        public int DistinctReagentsCount
        {
            get 
            {
                return Reagents
                    .Select(i => i.ReagentID)
                    .Distinct()
                    .Count();
            }
        }

    }
}
